define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {

		function get_data_distributordemandList(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"agenterdemand": [' +
					'{"info_id": "001","brand_id": "001","brand_name": "世达","releas_time":"2017-11-11 12:12:50","status":"","cat_type": [' +
					'{"id": "001","name": "品类_001"},' +
					'{"id": "002","name": "品类_002"}],"region": [' +
					'{"id": "001","name": "上海"},' +
					'{"id": "002","name": "北京"}],"num": 20,"hasnum": 2,"surplus": 18,"store": [' +
					'{"id": "001","name": "店铺_001","apply_time": "2017/01/01 09:00:00","status": "通过"},' +
					'{"id": "002","name": "店铺_002","apply_time": "2017/01/02 09:00:00","status": "审核中"}]},' +
					'{"brand_id": "002","brand_name": "博士","releas_time":"2017-11-11 12:12:50","status":"","cat_type": [' +
					'{"id": "001","name": "品类_001"},' +
					'{"id": "002","name": "品类_002"}],"region": [' +
					'{"id": "001","name": "上海"},' +
					'{"id": "002","name": "北京"}],"num": 20,"hasnum": 2,"surplus": 18,"store": [' +
					'{"id": "001","name": "店铺_001","apply_time": "2017/01/01 09:00:00","status": "通过"},' +
					'{"id": "002","name": "店铺_002","apply_time": "2017/01/02 09:00:00","status": "审核中"}]}]},"session": "7311da98bd0f18eb15a96bcb263f4153"}';

				return JSON.parse(result);
			} else {
				return result;
			}
		};
		function get_data_answer(result){
			if(false) {
				result = '{"success": true,"msg": "","result": {"store_id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}
		//返回信息
		return {
			//寻找代理商一览
			distributordemand_list: function(nPage,callback,calldone) {
				//				//post请求
				Http.post({
						method: 'member.agenterdemand.getlist',
						pagelimit: 10,
						nPage: nPage,

					},
					function(result) {
						//请求成功
						if(callback)
							callback(get_data_distributordemandList(result).result);
					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
						if(calldone)
						calldone();
					}
				);
				//
			},
			answer_distributor:function(info_id,store_id,answer,resean,callback){
				Http.post({
					method:'member.agenterdemand.answer',
					info_id:info_id,
					store_id:store_id,
					answer:answer,
					resean:resean
				},function(result){
					if(callback)
					callback(get_data_answer(result));
				},function(e){
					
				},function(){
					
				})
			},
			delete_agent:function(info_id,callback){
				Http.post({
					method:'member.agenterdemand.delete',
					info_id:info_id
				},function(result){
					if(callback)
					callback(result);
				})
			},
			angter_detail:function(apply_id,callback){
				Http.post({
					method:'member.agentdemand.detail',
					apply_id:apply_id
				},function(result){
					if(callback)
					callback(result.result);
				})
			}

		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Distributor_list", factory);
});